<?php
class Pjtjz_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($xxfget['type'])?$xxfget['type']:false;
        if(!$type){
        	$result=xdb::getInstance()->getarray('select tname,term,AVG(fenshu) as af,count(ttid) as countt from temstu_tct as stct,temstuclass as tc,temteacher as ter,temclassteacher as tct where stct.tctid=tct.id and tct.ttid=ter.id and tct.tcid=tc.id GROUP BY ttid');
        	$avgf=0;
        	foreach ($result as $row){
        	    $avgf+=$row['af'];
        	}
        	$avgf=$avgf/count($result);
        	$this::show('pjtjz',compact('result','avgf'));
        }elseif ($type=="xiangxi"){
        	$tctid=$xxfget['tctid'];
        	$tcid=$xxfget['tcid'];
        	$allpj=xdb::getInstance()->getcol("select pingjia from temclassteacher as tct,temteacher as ter,temstuclass as tc,temstu_tct as stct where tct.tcid=tc.id and tct.ttid=ter.id and stct.tctid=tct.id and tcid=".$tcid);
        	//select pingjia from temclassteacher as tct,temteacher as ter,temstuclass as tc,temstu_tct as stct where tct.tcid=tc.id and tct.ttid=ter.id and stct.tctid=tct.id and tcid=6
        	$avgtjxx=array();
        	$zongrenshu=0;
        	$fen=array('A'=>5,'B'=>4,'C'=>3,'D'=>2);
        	for($i=0;$i<count($allpj);$i++){
        	    $zongrenshu++;
        	    for($k=0;$k<20;$k++){
        	        $avgtjxx[$k]=(isset($avgtjxx[$k])?$avgtjxx[$k]:0)+$fen[$allpj[$i][$k]];
        	    }
        	}
        	$result=xdb::getInstance()->getarray('select * from temstu_tct where tctid = '.$tctid);
        	$tjxx=array();
        	foreach ($result as $row){
        	    for($i=0;$i<strlen($row['pingjia']);$i++){
        	        $tjxx[$i]=(isset($tjxx[$i])?$tjxx[$i]:"").$row['pingjia'][$i];
        	    }
        	}
        	$this::show('pjtjz_xiangxi',compact('result','tjxx','avgtjxx','zongrenshu'));
        }elseif ($type=="class"){
            $result=xdb::getInstance()->getarray('select tct.id as tctid,tcid,ttid,term,tname,cname from temclassteacher as tct,temteacher as ter,temstuclass as tc where tct.tcid=tc.id and tct.ttid=ter.id');
            $classavgfen=xdb::getInstance()->getarray('select tcid,avg(fenshu) as af from temclassteacher as tct,temteacher as ter,temstuclass as tc,temstu_tct as stct where tct.tcid=tc.id and tct.ttid=ter.id and stct.tctid=tct.id GROUP BY tcid');
            $countbeizhu=xdb::getInstance()->getarray('select ttid,tcid,count(1) as countbeizhu from temstu_tct as stct,temclassteacher as tct where stct.tctid=tct.id and LENGTH(TRIM(beizhu)) >4 group by tcid,ttid');
            $cavgf=array();
            $cbeizhu=array();
            foreach ($classavgfen as $row){
                $cavgf[$row['tcid']]=$row['af'];
            }
            foreach ($countbeizhu as $row){
                $cbeizhu[$row['ttid']."_".$row['tcid']]=$row['countbeizhu'];
            }
            $this::show('pjtjz_class',compact('result','cavgf','cbeizhu'));
        }
    }
}